<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>state的简写方式</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
</head>

<body>
    <div id="app"></div>
    <script type="text/babel">
        // 定义一个 Weather 组件
        class Weather extends React.Component {
            state = {
                isHot: true
            }

            render() {
                const { isHot } = this.state
                return <h1 onClick={this.changeWeather}>今天天气很{isHot ? '炎热' : '凉爽'}</h1>
            }

            changeWeather = () => {
                console.log(this)
                const isHot = this.state.isHot
                this.setState({
                    isHot: !isHot // 取反赋值
                })
            }
        }
        ReactDOM.render(<Weather />, document.querySelector('#app'))

    </script>
</body>

</html>